package HTTPRecieveParser;

import HTTPSendIntegrator.MmsMessageException;

public class ReadRecInd {
	private String readReportReqMessage;
	
	protected static final String NL = "\r\n";
	
	public static final String MMS_MESSAGE_TYPE = "X-Mms-Message-Type:";
	public static final String MMS_VERSION = "X-Mms-MMS-Version:";
	public static final String MMS_MESSAGE_ID = "Message-ID:";
	public static final String MMS_TO = "To:"; 
	public static final String MMS_FROM = "From:"; 
	public static final String MMS_READ_STATUS = "X-Mms-Read-Status:";
	public static final String MMS_DATE = "Date:";

	private String mmsMessageType;
	private String mmsVersion;
	private String mmsMessageId;
	private String mmsTo;
	private String mmsFrom;
	private String mmsReadStatus;
	private String mmsDate;

	public String getMessageType(){
		return mmsMessageType;
	}

	public String getMessageVersion(){
		return mmsVersion;
	}
	
	public String getMessageId(){
		return mmsMessageId;
	}

	public String getTo(){
		return mmsTo;
	}

	public String getFrom(){
		return mmsFrom;
	}

	public String getReadStatus(){
		return mmsReadStatus;
	}
	
	public String getDate(){
		return mmsDate;
	}	
	
	public ReadRecInd(String readReportReqMessage) throws MmsMessageException {
		this.readReportReqMessage = readReportReqMessage;
	}
	
	public void decodeMessage(){
		try{
			String[] result = readReportReqMessage.split(NL);			
			int i=0;
			for(i=0; i<result.length; i++)
			{
				if(result[i].startsWith(MMS_MESSAGE_TYPE))
					mmsMessageType=(result[i].substring((result[i].indexOf(':'))+2));
				
				else if(result[i].startsWith(MMS_VERSION))
					mmsVersion=result[i].substring((result[i].indexOf(':'))+2);
				
				else if(result[i].startsWith(MMS_MESSAGE_ID))
					mmsMessageId=result[i].substring((result[i].indexOf(':'))+2);
				
				else if(result[i].startsWith(MMS_TO))
					mmsTo=result[i].substring((result[i].indexOf(':'))+2);
				
				else if(result[i].startsWith(MMS_FROM))
					mmsFrom=result[i].substring((result[i].indexOf(':'))+2);
				
				else if(result[i].startsWith(MMS_READ_STATUS))
					mmsReadStatus=result[i].substring((result[i].indexOf(':'))+2);
				
				else if(result[i].startsWith(MMS_DATE))
					mmsDate=result[i].substring((result[i].indexOf(':'))+2);
			}			
		}catch (ArrayIndexOutOfBoundsException e){
			System.out.println("Malformed response message");
		}
	}
}
